using B.S.Passport.Infacetrue;
using B.S.Passport.Write.API;
using Microsoft.EntityFrameworkCore;
using DAL;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    var path = System.AppDomain.CurrentDomain.BaseDirectory + "B.S.Passport.Write.API.xml";
    if (System.IO.File.Exists(path))
    {
        x.IncludeXmlComments(path, true);
    }
});

// 注册数据库上下文
builder.Services.AddDbContext<DbcontextWMS>(c => c.UseSqlServer(builder.Configuration.GetConnectionString("Db")));
// 注册仓储
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseReository<>));
// 注册 DBHelper
builder.Services.AddScoped<DBHelper1>();
//ע��AutoMapper
builder.Services.AddAutoMapper(typeof(AutoMapperProfile));
////ע���н���
//builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
//注册中介者
builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()));
builder.Services.AddAutoMapper(typeof(AutoMapperProfile));

var app = builder.Build();
app.UseCors(p => p.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
    app.UseSwagger();
    app.UseSwaggerUI();
//}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthorization();
app.UseCors(c => c.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin());
app.MapControllers();

app.Run();